//
//  HUD.m
//
//  Created by isaced on 14-5-27.
//  Copyright (c) 2014年 isaced. All rights reserved.
//

#import "HUD.h"

#define kDefaultDelay 1.0
#define kDefaultYOffset 200.f

@implementation HUD


-(void)showTimeWithText:(NSString *)str{
    [self setLabelText:str];
    [self setYOffset:kDefaultYOffset];
    [self show:YES];
    [self hide:YES afterDelay:kDefaultDelay];
}

-(void)showTimeWithText:(NSString *)str yOffset:(float)yOffset{
    [self setLabelText:str];
    [self setYOffset:yOffset];
    [self show:YES];
    [self hide:YES afterDelay:kDefaultDelay];
}

- (void)showForTime:(NSTimeInterval)s WithText:(NSString *)str{
    [self setLabelText:str];
    [self setYOffset:kDefaultYOffset];
    [self show:YES];
    [self hide:YES afterDelay:s];
}

+ (instancetype)sharedHUD{
    static HUD *_sharedClient;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedClient = [[HUD alloc] init];
    });
    
    // 防止 Alert 之类的 window 挡住
    if (!_sharedClient.superview) {
        UIWindow *window = [UIApplication sharedApplication].keyWindow;
        [window addSubview:_sharedClient];
    }
    
    return _sharedClient;
}

+ (instancetype)sharedHUDText{
    static HUD *_sharedClient;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedClient = [[HUD alloc] init];
        //为了不让提示信息页面截获焦点
        _sharedClient.userInteractionEnabled = NO;
        _sharedClient.mode = MBProgressHUDModeText;
        _sharedClient.yOffset = kDefaultYOffset;
        _sharedClient.labelFont = [UIFont systemFontOfSize:14.f];
        _sharedClient.margin = 10;
        _sharedClient.cornerRadius = 3;
    });
    
    // 防止 Alert 之类的 window 挡住
    if (!_sharedClient.superview) {
        UIWindow *window = [UIApplication sharedApplication].keyWindow;
        [window addSubview:_sharedClient];
    }
    return _sharedClient;
}

@end
